package com.gz.mylife.adapter;

import java.util.ArrayList;
import java.util.List;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.view.ViewGroup;

import com.zl.smartmall.library.util.CrashHandler;

public class AdvertFragmentAdapter extends FragmentStatePagerAdapter {
		
		private static final String TAG = AdvertFragmentAdapter.class.getSimpleName();
		private List<AdvertFragment> mAdvertFragments;
		
		public AdvertFragmentAdapter(FragmentManager fm) {
			this(fm, null);
		}
		
		public AdvertFragmentAdapter(FragmentManager fm, List<AdvertFragment> fragments) {
			super(fm);
			mAdvertFragments = new ArrayList<AdvertFragment>();
			if(fragments != null) {
				mAdvertFragments.addAll(fragments);
			}
		}

		@Override
		public Fragment getItem(int position) {
			return mAdvertFragments.get(position);
		}

		@Override
		public int getCount() {
			return mAdvertFragments.size();
		}
		
		@Override
		public void destroyItem(ViewGroup container, int position, Object object) {
			super.destroyItem(container, position, object);
		}

		@Override
		public Object instantiateItem(ViewGroup container, int position) {

			Object obj = super.instantiateItem(container, position);
			CrashHandler.d(TAG, "FragmentAdapter's instantiateItem");
			return obj;
		}
		
		public void addAll(List<AdvertFragment> fragments) {
			mAdvertFragments.addAll(fragments);
		}
		
		public void clear() {
			mAdvertFragments.clear();
		}
	}